package com.job.yangshida.homework0715;

import java.lang.management.ManagementFactory;

/**
 * @author 杨士达
 * @version 1.0
 * @since 2022-07-16 12:02:56
 */
public class StringCompare {
    public static void main(String[] args) {
        //能比较的类实现了接口comparable
        String name="jake",name2="j";
        System.out.println(name.compareTo(name2));//比的长度
         name="a";name2="k";
        System.out.println(name.compareTo(name2));//比的z在字典里的顺序
//contains是否包含
        name="System.out.println(name.compareTo(name2));//比的z在字典里";
        System.out.println(name.contains("Sy"));
        //是否以...开始
        System.out.println(name.startsWith("里"));
        System.out.println(name.endsWith("里"));
        //f返回某子串第一次出现的位置
        //          在指定位置之后第一次出现的位置
        //某有就返回-1
        System.out.println(name.indexOf('i'));
        System.out.println(name.indexOf('i', 18));
        int i=name.indexOf("name");
        System.out.println("name第一次出现"+i);
        System.out.println("name第2次出现"+name.indexOf("name", i + 4));
        //qiu求System.out.println(name.compareTo(name2));//比的z在字典里,出现了几次name
        int count=0,index=-1,startIndex=0;
        while ((index=name.indexOf("name",startIndex))!=-1){
            startIndex=index+4;
            count++;
        }
        System.out.println(name.length());
        System.out.println(count);
    }
}
